home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / MPW Related / MPW Interfaces / CIncludes / MIDI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  10.2 KB  |  274 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MIDI.h
  3.  
  4.     Copyright:    © 1983-1993 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Version:    System 7.1 for ETO #11
  8.     Created:    Tuesday, March 30, 1993 18:00
  9.  
  10. */
  11.  
  12. #ifndef __MIDI__
  13. #define __MIDI__
  14.  
  15. #ifndef __TYPES__
  16. #include <Types.h>
  17. #endif
  18.  
  19.  
  20. enum {
  21.  
  22.  
  23. #define midiToolNum 4                   /*tool number of MIDI Manager for SndDispVersion call*/
  24.  
  25.     midiMaxNameLen = 31,                /*maximum number of characters in port and client names*/
  26.  
  27. /* Time formats */
  28.     midiFormatMSec = 0,                 /*milliseconds*/
  29.     midiFormatBeats = 1,                /*beats*/
  30.     midiFormat24fpsBit = 2,             /*24 frames/sec.*/
  31.     midiFormat25fpsBit = 3,             /*25 frames/sec.*/
  32.     midiFormat30fpsDBit = 4,            /*30 frames/sec. drop-frame*/
  33.     midiFormat30fpsBit = 5,             /*30 frames/sec.*/
  34.     midiFormat24fpsQF = 6,              /*24 frames/sec. longInt format */
  35.     midiFormat25fpsQF = 7,              /*25 frames/sec. longInt format */
  36.     midiFormat30fpsDQF = 8,             /*30 frames/sec. drop-frame longInt format */
  37.     midiFormat30fpsQF = 9,              /*30 frames/sec. longInt format */
  38.     midiInternalSync = 0,               /*internal sync*/
  39.     midiExternalSync = 1,               /*external sync*/
  40.  
  41. /* Port types*/
  42.     midiPortTypeTime = 0,               /*time port*/
  43.     midiPortTypeInput = 1,              /*input port*/
  44.     midiPortTypeOutput = 2,             /*output port*/
  45.     midiPortTypeTimeInv = 3,            /*invisible time port*/
  46.  
  47. /* OffsetTimes  */
  48.     midiGetEverything = 0x7FFFFFFF,     /*get all packets, regardless of time stamps*/
  49.     midiGetNothing = 0x80000000,        /*get no packets, regardless of time stamps*/
  50.     midiGetCurrent = 0x00000000         /*get current packets only*/
  51. };
  52. enum {
  53.  
  54. /*    MIDI data and messages are passed in MIDIPacket records (see below).
  55.     The first byte of every MIDIPacket contains a set of flags
  56.    
  57.     bits 0-1    00 = new MIDIPacket, not continued
  58.                      01 = begining of continued MIDIPacket
  59.                      10 = end of continued MIDIPacket
  60.                     11 = continuation
  61.     bits 2-3     reserved
  62.   
  63.     bits 4-6      000 = packet contains MIDI data
  64.    
  65.                      001 = packet contains MIDI Manager message
  66.    
  67.     bit 7              0 = MIDIPacket has valid stamp
  68.                         1 = stamp with current clock */
  69.     midiContMask = 0x03,
  70.     midiNoCont = 0x00,
  71.     midiStartCont = 0x01,
  72.     midiMidCont = 0x03,
  73.     midiEndCont = 0x02,
  74.     midiTypeMask = 0x70,
  75.     midiMsgType = 0x00,
  76.     midiMgrType = 0x10,
  77.     midiTimeStampMask = 0x80,
  78.     midiTimeStampCurrent = 0x80,
  79.     midiTimeStampValid = 0x00,
  80.  
  81. /*    MIDI Manager MIDIPacket command words (the first word in the data field
  82.     for midiMgrType messages) */
  83.     midiOverflowErr = 0x0001,
  84.     midiSCCErr = 0x0002,
  85.     midiPacketErr = 0x0003,
  86.     midiMaxErr = 0x00FF,                /*all command words less than this value  are error indicators*/
  87.  
  88. /* Valid results to be returned by readHooks */
  89.     midiKeepPacket = 0,
  90.     midiMorePacket = 1,
  91.     midiNoMorePacket = 2,
  92.  
  93. /* Errors: */
  94.     midiNoClientErr = -250,             /*no client with that ID found*/
  95.     midiNoPortErr = -251                /*no port with that ID found*/
  96. };
  97. enum {
  98.     midiTooManyPortsErr = -252,         /*too many ports already installed in the system*/
  99.     midiTooManyConsErr = -253,          /*too many connections made*/
  100.     midiVConnectErr = -254,             /*pending virtual connection created*/
  101.     midiVConnectMade = -255,            /*pending virtual connection resolved*/
  102.     midiVConnectRmvd = -256,            /*pending virtual connection removed*/
  103.     midiNoConErr = -257,                /*no connection exists between specified ports*/
  104.     midiWriteErr = -258,                /*MIDIWritePacket couldn't write to all connected ports*/
  105.     midiNameLenErr = -259,              /*name supplied is longer than 31 characters*/
  106.     midiDupIDErr = -260,                /*duplicate client ID*/
  107.     midiInvalidCmdErr = -261,           /*command not supported for port type*/
  108.  
  109. /*     Driver calls: */
  110.     midiOpenDriver = 1,
  111.     midiCloseDriver = 2
  112. };
  113.  
  114. struct MIDIPacket {
  115.     unsigned char flags;
  116.     unsigned char len;
  117.     long tStamp;
  118.     unsigned char data[249];
  119. };
  120.  
  121. typedef struct MIDIPacket MIDIPacket;
  122. typedef MIDIPacket *MIDIPacketPtr;
  123.  
  124. struct MIDIClkInfo {
  125.     short sync;                         /*synchronization external/internal*/
  126.     long curTime;                       /*current value of port's clock*/
  127.     short format;                       /*time code format*/
  128. };
  129.  
  130. typedef struct MIDIClkInfo MIDIClkInfo;
  131.  
  132. struct MIDIIDRec {
  133.     OSType clientID;
  134.     OSType portID;
  135. };
  136.  
  137. typedef struct MIDIIDRec MIDIIDRec;
  138.  
  139. struct MIDIPortInfo {
  140.     short portType;                     /*type of port*/
  141.     MIDIIDRec timeBase;                 /*MIDIIDRec for time base*/
  142.     short numConnects;                  /*number of connections*/
  143.     MIDIIDRec cList[1];                 /*ARRAY [1..numConnects] of MIDIIDRec*/
  144. };
  145.  
  146. typedef struct MIDIPortInfo MIDIPortInfo;
  147. typedef MIDIPortInfo *MIDIPortInfoPtr, **MIDIPortInfoHdl;
  148.  
  149. struct MIDIPortParams {
  150.     OSType portID;                      /*ID of port, unique within client*/
  151.     short portType;                     /*Type of port - input, output, time, etc.*/
  152.     short timeBase;                     /*refnum of time base, 0 if none*/
  153.     long offsetTime;                    /*offset for current time stamps*/
  154.     Ptr readHook;                       /*routine to call when input data is valid*/
  155.     long refCon;                        /*refcon for port (for client use)*/
  156.     MIDIClkInfo initClock;              /*initial settings for a time base*/
  157.     Str255 name;                        /*name of the port, This is a real live string, not a ptr.*/
  158. };
  159.  
  160. typedef struct MIDIPortParams MIDIPortParams;
  161. typedef MIDIPortParams *MIDIPortParamsPtr;
  162.  
  163. struct MIDIIDList {
  164.     short numIDs;
  165.     OSType list[1];
  166. };
  167.  
  168. typedef struct MIDIIDList MIDIIDList;
  169. typedef MIDIIDList *MIDIIDListPtr, **MIDIIDListHdl;
  170.  
  171.  
  172. #ifdef __cplusplus
  173. extern "C" {
  174. #endif
  175.  
  176. /* 
  177.     
  178.          Prototype Declarations for readHook and timeProc
  179.         
  180.          extern pascal short myReadHook(MIDIPacketPtr myPacket, long myRefCon);
  181.          extern pascal void myTimeProc(long curTime, long myRefCon);
  182.         
  183.          MIDI Manager Routines
  184. */
  185.  
  186. pascal long SndDispVersion(short toolnum); 
  187. pascal OSErr MIDISignIn(OSType clientID,long refCon,Handle icon,ConstStr255Param name)
  188.     = {0x203C,0x0004,midiToolNum,0xA800}; 
  189. pascal void MIDISignOut(OSType clientID)
  190.     = {0x203C,0x0008,midiToolNum,0xA800}; 
  191. pascal MIDIIDListHdl MIDIGetClients(void)
  192.     = {0x203C,0x000C,midiToolNum,0xA800}; 
  193. pascal void MIDIGetClientName(OSType clientID,Str255 name)
  194.     = {0x203C,0x0010,midiToolNum,0xA800}; 
  195. pascal void MIDISetClientName(OSType clientID,ConstStr255Param name)
  196.     = {0x203C,0x0014,midiToolNum,0xA800}; 
  197. pascal MIDIIDListHdl MIDIGetPorts(OSType clientID)
  198.     = {0x203C,0x0018,midiToolNum,0xA800}; 
  199. pascal OSErr MIDIAddPort(OSType clientID,short BufSize,short *refnum,MIDIPortParamsPtr init)
  200.     = {0x203C,0x001C,midiToolNum,0xA800}; 
  201. pascal MIDIPortInfoHdl MIDIGetPortInfo(OSType clientID,OSType portID)
  202.     = {0x203C,0x0020,midiToolNum,0xA800}; 
  203. pascal OSErr MIDIConnectData(OSType srcClID,OSType srcPortID,OSType dstClID,
  204.     OSType dstPortID)
  205.     = {0x203C,0x0024,midiToolNum,0xA800}; 
  206. pascal OSErr MIDIUnConnectData(OSType srcClID,OSType srcPortID,OSType dstClID,
  207.     OSType dstPortID)
  208.     = {0x203C,0x0028,midiToolNum,0xA800}; 
  209. pascal OSErr MIDIConnectTime(OSType srcClID,OSType srcPortID,OSType dstClID,
  210.     OSType dstPortID)
  211.     = {0x203C,0x002C,midiToolNum,0xA800}; 
  212. pascal OSErr MIDIUnConnectTime(OSType srcClID,OSType srcPortID,OSType dstClID,
  213.     OSType dstPortID)
  214.     = {0x203C,0x0030,midiToolNum,0xA800}; 
  215. pascal void MIDIFlush(short refnum)
  216.     = {0x203C,0x0034,midiToolNum,0xA800}; 
  217. pascal ProcPtr MIDIGetReadHook(short refnum)
  218.     = {0x203C,0x0038,midiToolNum,0xA800}; 
  219. pascal void MIDISetReadHook(short refnum,ProcPtr hook)
  220.     = {0x203C,0x003C,midiToolNum,0xA800}; 
  221. pascal void MIDIGetPortName(OSType clientID,OSType portID,Str255 name)
  222.     = {0x203C,0x0040,midiToolNum,0xA800}; 
  223. pascal void MIDISetPortName(OSType clientID,OSType portID,ConstStr255Param name)
  224.     = {0x203C,0x0044,midiToolNum,0xA800}; 
  225. pascal void MIDIWakeUp(short refnum,long time,long period,ProcPtr timeProc)
  226.     = {0x203C,0x0048,midiToolNum,0xA800}; 
  227. pascal void MIDIRemovePort(short refnum)
  228.     = {0x203C,0x004C,midiToolNum,0xA800}; 
  229. pascal short MIDIGetSync(short refnum)
  230.     = {0x203C,0x0050,midiToolNum,0xA800}; 
  231. pascal void MIDISetSync(short refnum,short sync)
  232.     = {0x203C,0x0054,midiToolNum,0xA800}; 
  233. pascal long MIDIGetCurTime(short refnum)
  234.     = {0x203C,0x0058,midiToolNum,0xA800}; 
  235. pascal void MIDISetCurTime(short refnum,long time)
  236.     = {0x203C,0x005C,midiToolNum,0xA800}; 
  237. pascal void MIDIStartTime(short refnum)
  238.     = {0x203C,0x0060,midiToolNum,0xA800}; 
  239. pascal void MIDIStopTime(short refnum)
  240.     = {0x203C,0x0064,midiToolNum,0xA800}; 
  241. pascal void MIDIPoll(short refnum,long offsetTime)
  242.     = {0x203C,0x0068,midiToolNum,0xA800}; 
  243. pascal OSErr MIDIWritePacket(short refnum,MIDIPacketPtr packet)
  244.     = {0x203C,0x006C,midiToolNum,0xA800}; 
  245. pascal Boolean MIDIWorldChanged(OSType clientID)
  246.     = {0x203C,0x0070,midiToolNum,0xA800}; 
  247. pascal long MIDIGetOffsetTime(short refnum)
  248.     = {0x203C,0x0074,midiToolNum,0xA800}; 
  249. pascal void MIDISetOffsetTime(short refnum,long offsetTime)
  250.     = {0x203C,0x0078,midiToolNum,0xA800}; 
  251. pascal long MIDIConvertTime(short srcFormat,short dstFormat,long time)
  252.     = {0x203C,0x007C,midiToolNum,0xA800}; 
  253. pascal long MIDIGetRefCon(short refnum)
  254.     = {0x203C,0x0080,midiToolNum,0xA800}; 
  255. pascal void MIDISetRefCon(short refnum,long refCon)
  256.     = {0x203C,0x0084,midiToolNum,0xA800}; 
  257. pascal long MIDIGetClRefCon(OSType clientID)
  258.     = {0x203C,0x0088,midiToolNum,0xA800}; 
  259. pascal void MIDISetClRefCon(OSType clientID,long refCon)
  260.     = {0x203C,0x008C,midiToolNum,0xA800}; 
  261. pascal short MIDIGetTCFormat(short refnum)
  262.     = {0x203C,0x0090,midiToolNum,0xA800}; 
  263. pascal void MIDISetTCFormat(short refnum,short format)
  264.     = {0x203C,0x0094,midiToolNum,0xA800}; 
  265. pascal void MIDISetRunRate(short refnum,short rate,long time)
  266.     = {0x203C,0x0098,midiToolNum,0xA800}; 
  267. pascal Handle MIDIGetClientIcon(OSType clientID)
  268.     = {0x203C,0x009C,midiToolNum,0xA800}; 
  269. #ifdef __cplusplus
  270. }
  271. #endif
  272.  
  273. #endif
  274.